package com.guan.ordering_sys.generator.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guan.ordering_sys.common.PageResult;
import com.guan.ordering_sys.common.ResultApi;
import com.guan.ordering_sys.common.StateCode;
import com.guan.ordering_sys.generator.service.impl.BusinessModelServiceImpl;
import com.guan.ordering_sys.vo.BusinessModelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 *  前端控制器
 * </p>
 *
 * @author 林煜岚
 * @since 2021-06-23
 */

@Api(tags = "经营模式接口")
@RestController
@RequestMapping("/api/business-model")
public class BusinessModelController {
    @Autowired
    BusinessModelServiceImpl businessModelService;

    @ApiOperation("获取经营模式")
    @GetMapping("/getBusinessModel")
    public ResultApi getBusinessModel(@ApiParam("当前页面") int pageNum, @ApiParam("页面大小") int pageSize) {
        Page<BusinessModelVo> businessModelVoPage = new Page<>();
        businessModelVoPage.setSize(pageSize);
        businessModelVoPage.setCurrent(pageNum);
        IPage<BusinessModelVo> businessModelVoIPage = businessModelService.getBusinessModel(businessModelVoPage);
        if (businessModelVoIPage != null) {
            PageResult<BusinessModelVo> businessModelVoPageResult = new PageResult<>(businessModelVoIPage.getRecords().size(), businessModelVoIPage.getRecords());
            return ResultApi.success(businessModelVoPageResult);
        } else {
            return ResultApi.errorNotData(StateCode.FAIL);
        }
    }
}

